﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OverStore.Configuration.ObjectRepository.Accessors;

namespace OverStore.TutorialAsTest.UnitTest.Components.Accessor
{
    [TestClass]
    public class PropertyAccessorTest
    {
        [TestMethod]
        public void Accessor_PropertyAccessor_ReadWrite()
        {
            var accessor = new PropertyAccessor<SimpleTestClass, string>("TestField");
            var item = new SimpleTestClass()
            {
                TestField = "Value"
            };

            Assert.AreEqual(item.TestField, accessor.GetValue(item));

            const string newValue = "NewValue";
            accessor.SetValue(item, newValue);

            Assert.AreEqual(newValue, item.TestField);
        }

        [TestMethod]
        public void Accessor_PropertyAccessor_ReadWriteInherit()
        {
            var accessor = new PropertyAccessor<SimpleTestClass, string>("TestField");
            var item = new SimpleClassInheritor()
            {
                TestField = "Value"
            };

            Assert.AreEqual(item.TestField, accessor.GetValue(item));

            const string newValue = "NewValue";
            accessor.SetValue(item, newValue);

            Assert.AreEqual(newValue, item.TestField);
        }


    }
}
